home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-08  |  2.7 KB  |  135 lines

  1.  
  2. /* Copyright (c) CNIDR (see file COPYRIGHT, included in this distribution) */
  3.  
  4. /* config.c: 
  5.  *  creates a header file with details on a machine's representation of 
  6.  *  numbers, alignment requirements, etc, etc.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include "Defaults.tmpl"
  11.  
  12. #ifdef TIME_WITH_SYS_TIME 
  13. /* #ifdef TM_IN_SYS_TIME */
  14. #include <sys/time.h>
  15. #include <time.h>
  16. #else
  17. #ifdef HAVE_SYS_TIME_H
  18. #include <sys/time.h>
  19. #else
  20. #include <time.h>
  21. #endif
  22. #endif
  23.  
  24. #define SHORT_CODE 0
  25. #define INT_CODE   1
  26. #define LONG_CODE  2
  27. #define CHAR_CODE  3
  28.  
  29. typedef struct _short_test {
  30.   char c;
  31.   unsigned short s;
  32. } short_test;
  33.  
  34. typedef struct _long_test {
  35.   char c;
  36.   unsigned long l;
  37. } long_test;
  38.  
  39. typedef struct _int_test {
  40.   char c;
  41.   unsigned int i;
  42. } int_test;
  43.  
  44.  
  45. int main() 
  46. {
  47.  
  48.   short_test st;
  49.   long_test lt;
  50.   int_test it;
  51.  
  52.   int four_byte;
  53.   int two_byte;
  54.   int one_byte;
  55.  
  56.   unsigned int i,*ip;
  57.   unsigned long l,*lp;
  58.   unsigned short s,*sp;
  59.   char c;
  60.   unsigned char *cp;
  61.  
  62.   printf("#ifndef CONFIG_H\n");
  63.   printf("#define CONFIG_H\n");
  64.   printf("#include \"Defaults.tmpl\"\n");
  65.   if(sizeof(char) == 1) {
  66.     printf("#define ONE_BYTE char\n");
  67.     one_byte = CHAR_CODE;
  68.   } else {
  69.     fprintf(stderr,
  70.         "Error: chars are %d bytes long. Can't define ONE_BYTE\n",sizeof(char));
  71.     exit(1);
  72.   }
  73.  
  74.   if(sizeof(int) == 2) {
  75.     printf("#define TWO_BYTE int\n");
  76.     two_byte = INT_CODE;
  77.   } else {
  78.     if(sizeof(short) == 2) {
  79.       printf("#define TWO_BYTE short\n");
  80.       two_byte = SHORT_CODE;
  81.     } else {
  82.       fprintf(stderr,"Error: don't know how to define TWO_BYTE\n");
  83.       exit(1);
  84.     }
  85.   }
  86.  
  87.   if(sizeof(int) == 4) {
  88.     printf("#define FOUR_BYTE int\n");
  89.     four_byte = INT_CODE;
  90.   } else {
  91.     if(sizeof(long) == 4) {
  92.       printf("#define FOUR_BYTE long\n");
  93.       four_byte = LONG_CODE;
  94.      } else {
  95.        fprintf(stderr,"Error: don't know how to define FOUR_BYTE\n");
  96.      }
  97.   }
  98.     
  99.       
  100.   if(two_byte == SHORT_CODE) {
  101.     printf("#define TWO_BYTE_ALIGN %d\n",(int)(&st.s)-(int)(&st.c));
  102.   } else {
  103.     if (two_byte == INT_CODE) {
  104.       printf("#define TWO_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  105.     }
  106.   }
  107.   if(four_byte == INT_CODE) {
  108.     printf("#define FOUR_BYTE_ALIGN %d\n",(int)(&it.i)-(int)(&it.c));
  109.   } else {
  110.     if(four_byte == LONG_CODE) {
  111.       printf("#define FOUR_BYTE_ALIGN %d\n",(int)(<.l)-(int)(<.c));
  112.     }
  113.   }
  114.  
  115.   l=0xdeadbeef;
  116.  
  117.   
  118.   cp=(unsigned char*)&l;
  119.  
  120.   if(*cp == 0xde) {
  121.     printf("#ifndef BIGENDIAN\n#define BIGENDIAN\n#endif\n");
  122.   } else {
  123.     if(*cp == 0xef) {
  124.       printf("#ifndef  LITTLEENDIAN\n#define LITTLEENDIAN\n#endif\n");
  125.       } else {
  126.     fprintf(stderr,"Error: can't find out byte order\n");
  127.     exit(1);
  128.       }
  129.   }
  130.   printf("#define FILE_WRITE_DATE_SIZE %d\n",  sizeof(time_t));
  131.   printf("#endif /* CONFIG_H */\n");
  132.   exit(0);
  133. }
  134.   
  135.